package vi

var ViDemoTpl = `
package vi

import (
    "context"
    "fmt"
    "github.com/gin-gonic/gin"
    "net/http"
    "strconv"
    "{{.App}}/pkg/storage/verify"
    "{{.App}}/proto/pb"
)

type VideoHandler struct {
    VideoClient pb.VisrvClient
}

func (v *VideoHandler) Register(c *gin.Context) {
    age := c.PostForm("age")
    a, _ := strconv.Atoi(age)
    name := c.PostForm("name")

    data := verify.ValidateUser(&verify.User{
        Name: name,
        Age:  a,
    })

    if data != "" {
        c.JSON(http.StatusUnauthorized, gin.H{"msg": data})
        return
    }

    u, err := v.VideoClient.AddUsers(context.Background(), &pb.AddUsersReq{
        Name: name,
        Age:  int64(a),
    })

    if err != nil {
        fmt.Println(err)
        c.JSON(http.StatusInternalServerError, gin.H{"msg": "服务器内部错误"})
        return
    }

    c.JSON(http.StatusOK, gin.H{"msg": u})
}
`
